<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Gafs extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     * 		http://localhost/ci/index.php/gafs
     *	- or -  
     * 		http://localhost/ci/index.php/gafs/index
     *	- or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://localhost/ci/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/gafs/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index() {
        $userList = array(
            'boo_online' => md5('lazyBoo'),
            'gafs' => md5('fantasy7Taur&')
        );
        $userInput = $this->input->post('booUser');
        $passInput = $this->input->post('booPass');

        if($userInput != '' && $passInput != '') {
            if(array_key_exists($userInput, $userList)) {
                if($userList[$userInput] == md5($passInput)) {
                    $this->session->set_flashdata('errorMessage','');
                    $loggedInData = array(
                        'booUser'  => $userInput,
                        'booPass'  => $passInput,
                        'logged_in' => TRUE
                    );
                    $this->session->set_userdata($loggedInData);
                    redirect(base_url()."index.php/product/");
                } else {
                    $this->session->set_flashdata('errorMessage','Password does not match.');
                }
                
            }
            else {
                $this->session->set_flashdata('errorMessage','Username does not exist.');
                //redirect('gafs/index/');
            }
        }
        else {
            $this->session->set_flashdata('errorMessage','Username or password was empty.');
            //redirect('gafs/index/');
        }
        
        $this->load->view('gafs');
    }
    
    public function logout() {
        $loggedInData = array(
            'booUser'  => '',
            'booPass'  => '',
            'logged_in' => FALSE
        );
        $this->session->unset_userdata($loggedInData);
        redirect('gafs/index');
    }
}

/* End of file gafs.php */
/* Location: ./application/controllers/gafs.php */